package com.rech.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.rech.adapter.adapterInterface.BaseAdapter;
import com.rech.module.LogisticModule;
import com.rech.xbexpress3.R;

import java.io.IOException;
import java.util.List;

/**
 * Created by sunshine on 2020/9/15
 */
public class LogisticAdapter extends BaseAdapter<LogisticAdapter.LogisticHolder> {
    private Context context;
    private List<LogisticModule> data;

    public LogisticAdapter(Context context, @NonNull List<LogisticModule> data) {
        this.context = context;
        this.data = data;
    }


    @Override
    public LogisticAdapter.LogisticHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_logistic, parent, false);
        LogisticAdapter.LogisticHolder holder = new LogisticAdapter.LogisticHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final LogisticAdapter.LogisticHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.tvName.setText(data.get(position).getName());
        if (data.get(position).getName().contains("申通")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_shentong);
        } else if (data.get(position).getName().contains("中通")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_zhongtong);
        } else if (data.get(position).getName().contains("韵达")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_yunda);
        } else if (data.get(position).getName().contains("天天")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_tiantian);
        } else if (data.get(position).getName().contains("百世")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_baishi);
        } else if (data.get(position).getName().contains("圆通")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_yuantong);
        } else if (data.get(position).getName().contains("天天")) {
            holder.img_logic.setImageResource(R.mipmap.img_logic_tiantian);
        } else {
            holder.img_logic.setImageResource(R.mipmap.img_logic_rabbit);
        }
        if (data.get(position).isChecked()) {
            holder.itemView.setBackgroundResource(R.drawable.img_bg_select);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.yellow));
        } else {
            holder.itemView.setBackgroundResource(R.drawable.bg_blue_button_5);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.white));
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
                                               @Override
                                               public void onClick(View view) {
                                                   listener.onItemClick(position);
                                               }
                                           });
    }


    @Override
    public int getItemCount() {
        return data.size();
    }

    static class LogisticHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        ImageView img_logic;
        public LogisticHolder(View itemView) {
            super(itemView);

            tvName = itemView.findViewById(R.id.tv_logistic_name);
            img_logic = itemView.findViewById(R.id.img_logic);
        }
    }
}
